<html>
    <head>
        <title>天气预报</title>
        <meta charset="utf-8">
        <script src="jquery.js"></script><!--导入jquery文件-->
        <style>
            body{
                margin: 0;
                width: 100%;
                height: 100%;
                /*linear,线性。gradient:梯度，渐变。to bottom从上到下。*/
                background-image: linear-gradient(to bottom,rgb(15,105,205),rgb(100,170,240));
                color: white;
                text-align: center;
                /*text-shadow: 文本阴影：向右偏移量  向下偏移量  模糊程度  颜色*/
                text-shadow: 2px 2px 2px black;
                background-repeat: no-repeat;
                background-color: rgb(100, 170, 240);
            }
            header{                
                margin-top: 50px;
                font-size: 30px;
                font-family: initial;
            }
            
            main .pic{/*   .表示找到class为pic的标签*/
                /*width: 128px;*/
                height: 128px;
                background-image: url("days/duoyun.png");
                background-repeat: no-repeat;/*背景重复：不重复*/
                background-position: center;/*背景位置：居中*/
                margin: 40px auto 40px;/*间距，上、右、下、左*/
            }
            main .temperature{
                font-size: 30px;
                font-family:Arial;/*font-family: 字体类型*/
            }
            main .weather{
                font-size: 25px;
            }
            main .wind{
                font-size: 20px;
                line-height: 200%;
            }
            main .current{
                font-size: 15px;
            }
            section .pic{
                height: 64px;
                /*width: 64px;*/
                background-image: url("days/qing.png");
                background-position: center;
                background-size: contain;/*背景尺寸：居中*/
                background-repeat: no-repeat;
                margin: 20px;
                opacity: 0.8;/*opacity: 透明度0-1；0：全透明，1：不透明*/
            }
            section{
                width: 33.3%;
                margin-top: 50px;
                float: left;/*float: 浮动。以左侧为基准向右排列*/
                border-right: solid 2px rgba(200, 200, 200, 0.5);
                box-sizing: border-box;/*设置边框的添加方向，向内添加边框*/
                margin-bottom: 20px;
            }
            section:nth-child(3){
                border-right: 0;
            }
        </style>
    </head>
    <body>
        <header>信阳市</header>
        <main>
            <div class="pic">  </div>
            <!--sup:上标，sub：下标。可以无限嵌套-->
            <div class="temperature">7 ~ 10<sup>℃</sup></div>
            <div class="weather">多云</div>
            <div class="wind">东北风3~4级</div>
            <div class="current">实时温度：5℃，空气指数 57 you</div>
        </main>
        <footer>
            <section>
                <div class="week">周四</div>
                <div class="pic"></div>
                <div class="temperature">9~0℃</div>
                <div class="weather">晴</div>
                <div class="wind">微风</div>
            </section>
             <section>
                <div class="week">周四</div>
                <div class="pic"></div>
                <div class="temperature">9~0℃</div>
                <div class="weather">晴</div>
                <div class="wind">微风</div>
            </section>
             <section>
                <div class="week">周四</div>
                <div class="pic"></div>
                <div class="temperature">9~0℃</div>
                <div class="weather">晴</div>
                <div class="wind">微风</div>
            </section>
        </footer>
    </body>
    <script>
        $.getJSON("http://api.map.baidu.com/telematics/v3/weather?location=郑州市&output=json&ak=HI5M8212CwMHcQdv7xMsX6QU&callback=?",function(data){
            //alert(JSON.stringify(data));
            var results = data.results;//得到JSON数据的results数据
            var r = results[0];//得到results数组的第一个数据
            var city = r.currentCity;
            $("header").text(city);
            var days = r.weather_data;
            var today = days[0];
            var picurl = today.dayPictureUrl;
            var pic = picurl.substr(picurl.lastIndexOf("/"));//字符串处理，substr截取字符串（lastIndexof找到最后一个斜杠位置）
            // 今天天气
            $("main .pic").css("background-image","url(days"+pic+")");
            $("main .temperature").text(today.temperature);//var temperature = today.temperature;
                                                            //$("main .temperature").text(temperature);
            $("main .wind").text(today.wind);               // var wind = today.wind;
                                                            //$("main .wind").text(wind);  
            $("main .weather").text(today.weather);         //var weather = today.weather;
                                                             //$("main .weather").text(weather);
            var current = today.date.substr(today.date.lastIndexOf("："),3);//截取字符串。取最后一个冒号后面3个字符
            // 判断空气质量
            var air;
            if(r.pm25<=50){                                              
                air="优";
            }
            else if(r.pm25<=100){air="良";}
            else if(r.pm25<=150){air="轻微污染"}
            else if(r.pm25<=200){air="轻度污染"}
            else{air = "严重污染";}
            
            
            $("main .current").text("实时温度"+current+"，空气指数："+r.pm25+"   "+air);
            // 今后三天
            var sections = $("section");
            //sections.length:数组长度，避免数组越界。
            for (var i=0;i<sections.length;i++){
                var day = days[i+1];
                var sec = sections[i];
                $(".week",sec).text(day.date);
                var picurl = day.dayPictureUrl;
                var pic = picurl.substr(picurl.lastIndexOf("/"));
                $(".pic",sec).css("background-image","url(days"+pic+")");
                $(".temperature",sec).text(day.temperature);
                $(".weather",sec).text(day.weather);
                $(".wind",sec).text(day.wind);
            }
        });//$调用jquery。得到JSON数据
    </script>
</html>